package team.fivez.defaultmanage.dao.Impl;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import team.fivez.defaultmanage.dao.ApproverDao;
import team.fivez.defaultmanage.domain.Approver;

import javax.annotation.Resource;

@Repository
public class ApproverDaoImpl implements ApproverDao {

    @Resource
    private JdbcTemplate jdbcTemplate;


    //根据账号查询数量（用于判断用户是否存在)
    @Override
    public Integer getCountByApproverAccount(String approverAccount) {
        String sql="select count(*) from approver where approver_account=?";
        return jdbcTemplate.queryForObject(sql,Integer.class,approverAccount);
    }

    //根据账号查询审核人信息
    @Override
    public Approver getApproverByApproverAccount(String approverAccount) {
        String sql="select * from approver where approver_account=?";
        return jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<>(Approver.class),approverAccount);

    }

    //插入审核人信息
    @Override
    public int insertApprover(Approver approver) {
        String sql="insert into approver values(?,?,?)";
        String approverAccount = approver.getApproverAccount();
        String approverName = approver.getApproverName();
        String approverPassword = approver.getApproverPassword();
        return jdbcTemplate.update(sql,approverAccount,approverName,approverPassword);

    }
}
